
import { get, post, patch, del } from './fetch'

export async function getCourts({ branch_campus_id, status }) {
  'use server'
  try {
    const courts = await get('/api/v1/courts', { branch_campus_id, status })
    return courts
  } catch (error) {
    throw error
  }
}


export async function getCourt(id) {
  'use server'
  try {
    const court = await get(`/api/v1/courts/${id}`)
    return court
  } catch (error) {
    throw error
  }
}

export async function createCourt(court) {
  'use server'
  try {
    const newCourt = await post('/api/v1/courts', court)
    return newCourt
  } catch (error) {
    throw error
  }
}

export async function updateCourt(court) {
  'use server'
  try {
    const updatedCourt = await patch(`/api/v1/courts/${court.id}`, court)
    return updatedCourt
  } catch (error) {
    throw error
  }
}

export async function deleteCourt(id) {
  'use server'
  try {
    await del(`/api/v1/courts/${id}`)
  } catch (error) {
    throw error
  }
}
